package com.atguigu.test;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @author xzt
 * @create 2021-03-10 16:36
 */
public class MyTest2 {

    @Test
    public void test1() throws Exception {
        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("spring/spring-*.xml");
        JavaMailSenderImpl javaMailSender = (JavaMailSenderImpl) ioc.getBean("sendMail");

        javaMailSender.setDefaultEncoding("UTF-8");
        MimeMessage mail = javaMailSender.createMimeMessage();

        MimeMessageHelper helper = new MimeMessageHelper(mail);

        helper.setSubject("标题");

        StringBuilder content = new StringBuilder();

        content.append("<a href=\"http://www.baidu.com\">AAA</a>");

        helper.setText(content.toString(),true);
        helper.setFrom("admin@atguigu.com");
        helper.setTo("test@atguigu.com");

        javaMailSender.send(mail);
    }

}
